<?php
namespace backend\controllers;
use Yii;
use yii\web\Controller;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use common\models\LoginForm;
use common\models\Admin;
use backend\models\Clue;
use backend\models\FollowInfos;

/**
 * Clue controller
 */
class FollowInfosController extends Controller
{
    public $enableCsrfValidation = false;//开启防止crf攻击
    //public $layout='base';
    /**
     * @inheritdoc
     */

    /**
     * @inheritdoc
     */
    public function actions()
    {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
        ];
    }

    /**
     * 线索首页
     */
    public function actionIndex()
    {
        $followInfosList=FollowInfos::find()->joinWith('followType')->joinWith('followStatus')->joinWith('coordinationDegree')->joinWith('users')->orderBy('id DESC')->asArray()->all();
        $data['followInfosList']=$followInfosList;
        return $this->renderPartial('index',$data);
    }
    /**
     * 添加线索操作
     */

    /**
     * 添加跟进内容
     */
    public function actionEditFollowInfo(){
        $params=Yii::$app->request->post();
        $followType=getData($params['followType'],'请选择跟进方式');
        $followTime=getData($params['followTime'],'请选择跟进时间');
        $followContent=getData($params['followContent'],'请填写跟进内容');
        $coordinationId=getData($params['coordinationId'],'请选择配合程度');
        $followStatus=getData($params['followStatus'],'请选择跟进状态');
        $nextFollowTime=getData($params['nextFollowTime'],'请选择下次跟进时间');
        $clueId=$params['clueId'];
        $enterpriseId=$params['enterpriseId'];
        $type=$params['type'];
        $id=0;
        if($id>0){
            $followInfo=FollowInfos::findOne();
            if(empty($followInfo)){
                returnResult(100033,'该内容不存在');
            }

        }else{
            $followInfo=new FollowInfos();
        }
        $userInfo=getUserInfo();
        $followInfo->followType=$followType;
        $followInfo->followTime=strtotime($followTime);
        $followInfo->followContent=$followContent;
        $followInfo->coordinationId= $coordinationId;
        $followInfo->followStatus=$followStatus;
        $followInfo->nextFollowTime=strtotime($nextFollowTime);
        $followInfo->addTime=time();
        $followInfo->clueId=$clueId;
        $followInfo->enterpriseId=$enterpriseId;
        $followInfo->type=$type;
        $followInfo->responUserId=$userInfo['id'];
        $doResult=$followInfo->save();
        if($doResult){
            returnResult(0,'操作成功');
        }else{
            returnResult(100035,'操作失败');
        }

    }





}
?>
